//
//  ZConsultTableViewCell.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/20.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZConsultTableViewCell.h"
#import "ZConsumerView.h"
@interface ZConsultTableViewCell() {
    UIView * _grayView;
    UIImageView * _styleView; // 此条消息的状态
    UILabel * _contextLabel;
    ZConsumerView * _userView;
}
@end
@implementation ZConsultTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initlizeInterface];
    }
    return self;
}
- (void)setCModel:(ZConsultModel *)cModel {
    _cModel = cModel;
    _contextLabel.text = _cModel.title;
    _userView.timeLabel.text = _cModel.time;
    _cancelBtn.hidden = YES;
    if ([_cModel.status isEqualToString:@"0"]) {
        _styleView.image = [UIImage imageNamed:@"newweihuifu"];
        _cancelBtn.hidden = NO;
    }else if ([_cModel.status isEqualToString:@"1"]) {
        _styleView.image = [UIImage imageNamed:@"Label_reply_2"];
    }else if ([_cModel.status isEqualToString:@"2"]){
        _styleView.image = [UIImage imageNamed:@"newweifukun"];
    }else if ([_cModel.status isEqualToString:@"3"]) {
        _styleView.image = [UIImage imageNamed:@"newweipinglun"];
    }else if ([_cModel.status isEqualToString:@"4"]) {
        _styleView.image = [UIImage imageNamed:@"Label_reply_1"];
    }
    
}
- (void)initlizeInterface {
    [self makeAddsubView];
    [self addAllSubView];
    [self makeAllSubViewMasnoy];
}

- (void)makeAddsubView {
    _grayView = [[UIView alloc] init];
    _grayView.backgroundColor = MYGRAYCOLOR;
    _styleView = [[UIImageView alloc] init];
    _styleView.image = [UIImage imageNamed:@"Label_reply_1"];
    [_styleView setContentMode:UIViewContentModeLeft];
    // 修改imageView的填充属性
    _styleView.clipsToBounds = YES;
    
    _contextLabel = [[UILabel alloc] init];
    _contextLabel.numberOfLines = 3;
    _contextLabel.text = @"";
    _contextLabel.font = [UIFont systemFontOfSize:16];
    _contextLabel.textColor = KHBlackColor;
    
    _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelBtn setTitle:@"撤销" forState:UIControlStateNormal];
    [_cancelBtn setTitleColor:KHGreenColor forState:UIControlStateNormal];
    _cancelBtn.layer.borderColor = [KHGreenColor CGColor];
    _cancelBtn.layer.borderWidth = 1.0f;
    _cancelBtn.layer.cornerRadius = 2.5f;
    _cancelBtn.layer.masksToBounds = YES;
    _cancelBtn.hidden = YES;
    
    [_cancelBtn addTarget:self action:@selector(RescindBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _userView = [[ZConsumerView alloc] init];
}
- (void)addAllSubView {
    [self.contentView addSubview:_grayView];
    [self.contentView addSubview:_styleView];
    [self.contentView addSubview:_contextLabel];
    [self.contentView addSubview:_userView];
    [self.contentView addSubview:_cancelBtn];

    
}
- (void)makeAllSubViewMasnoy {
    [_grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.width.equalTo(self);
        make.height.offset(10*ysIZE);
    }];
    [_styleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(_grayView.mas_bottom);
        make.width.offset(200*xsIZE);
        make.height.offset(25*ysIZE);
    }];
    [_contextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(13*xsIZE);
        make.right.equalTo(self).offset(-15*xsIZE);
        make.top.equalTo(_grayView).offset(40*ysIZE);
        make.height.offset(65*ysIZE);
    }];
    [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-15*xsIZE);
        make.bottom.equalTo(self.contentView).offset(-12.5*ysIZE);
        make.height.offset(25*ysIZE);
        make.width.offset(70*ysIZE);
    }];
    [_userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self);
        make.left.equalTo(self);
        make.height.offset(30*ysIZE);
        make.top.equalTo(_contextLabel.mas_bottom).offset(15*ysIZE);
    }];
}

- (void)RescindBtnAction:(UIButton *)sender {
//    !self.GoDoctorVCBlock ? : self.GoDoctorVCBlock();
    !self.GoRescindBlock ? : self.GoRescindBlock();
}
@end
